Skip to content

Conversation

pdgendt
Copy link
Contributor

@pdgendt pdgendt commented Sep 26, 2025

A proof-of-concept using PR #96379 as an alternative for #74835.

Note that this loads the MAC address during driver initialization. A more complete (but complex) solution would be to move it to the network interface initialization.

@pdgendt pdgendt mentioned this pull request Sep 29, 2025
@pdgendt pdgendt force-pushed the nvmem-mac-address branch 2 times, most recently from 9afd50b to 8241eb8 Compare September 30, 2025 13:01
@pdgendt pdgendt changed the title [PoC] drivers: ethernet: sam_gmac: Use NVMEM cell to get MAC address [PoC] drivers: ethernet/wifi: Use NVMEM cell to get MAC address Sep 30, 2025
Given an ethernet MAC configuration struct, load a MAC address into a
provided array.

Signed-off-by: Pieter De Gendt <[email protected]>
Turn ethernet controller devicetree nodes into NVMEM consumers. Allow
passing mac-address cells.

Signed-off-by: Pieter De Gendt <[email protected]>
Rework the Atmel SAM GMAC driver to read a MAC address from the provided
NVMEM cell instead of using I2C commands directly.

Signed-off-by: Pieter De Gendt <[email protected]>
Create a generic Wi-Fi interface binding file which includes the
ethernet-controller.yaml bindings and include it in Nordic's WLAN
interface binding.

Signed-off-by: Pieter De Gendt <[email protected]>
Allow setting the MAC address for the nRF Wi-Fi interface with a
configuration derived from the devicetree.
This allows to use an NVMEM cell as MAC address storage.

Signed-off-by: Pieter De Gendt <[email protected]>
@pdgendt pdgendt force-pushed the nvmem-mac-address branch from 8241eb8 to 8ac0a2f Compare October 6, 2025 19:12
Copy link

sonarqubecloud bot commented Oct 6, 2025

Comment on lines +52 to +58
/* Copy the static part */
memcpy(mac_addr, cfg->addr, cfg->addr_len);

if (cfg->type == NET_ETH_MAC_STATIC && cfg->addr_len == NET_ETH_ADDR_LEN) {
/* Complete static address */
return 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have no difference between the static mac address and the default. as most drivers set the mac address from the dt as the initial value of the mac address in the data struct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit what you mean here? I don't fully understand.

This static MAC address is when you have the following:

eth-driver {
	local-mac-address = [02 02 03 04 05 06];
};

This should only ever be used during testing. An alternative is have the OUI in the static part:

eth-driver {
	local-mac-address = [00 04 25];
	zephyr,random-mac-address;
};
/* or */
eth-driver {
	local-mac-address = [00 04 25];
	nvmem-cells = <&mac_address>;
	nvmem-cell-names = "mac-address";
};

Maybe the naming should be changed in that case to something like mac-address-prefix?

enum net_eth_mac_type type;
uint8_t addr[NET_ETH_ADDR_LEN];
uint8_t addr_len;
struct nvmem_cell cell;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct nvmem_cell cell;
#if defined(CONFIG_NVMEM)
struct nvmem_cell cell;
#endif

should not increase size if not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants